clc;
close all;
clear all;

N = 8;
k = 2;
lower = 0.0;
upper = .9999999999;
step = 2^(-N);
qtl = 2^(-N-k);
ulp = 2^(-N);
num = (floor((upper-lower)/step) + 1);

lb = zeros(num,num);
ub = zeros(num,num);

id = 0;
for a = lower:step:upper
    for b = lower:step:upper
        id = id + 1;
        Z = a * b;
        Zl = rnd_down(Z, N);
        [Ztl, Zt] = trunc_mult(a, b, 0.0,N,N,N,k);      
        lb(id) = rnd_up(Zl - Zt, N + k);
        ub(id) = rnd_up(Zl - Zt + 2 * ulp, N + k);   
    end
end

lb = lb/qtl;
ub = ub/qtl;
figure; 
plot(lb(:), 'r-*');hold on;
plot(ub(:), 'b-+');
legend('Lower', 'Upper');